﻿#region << 文 件 说 明 >>

/*----------------------------------------------------------------
// 文件名称：TitleContent
// 创 建 者：杨程
// 创建时间：2021/10/14 9:33:10
// 文件版本：V1.0.0
// ===============================================================
// 功能描述：
//
//
//----------------------------------------------------------------*/

#endregion

namespace Vampirewal.Core.WPF.Theme;

/// <summary>
/// 带标题的内容控件
/// </summary>
public class TitleContent : ContentControl
{
    static TitleContent()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(TitleContent), new FrameworkPropertyMetadata(typeof(TitleContent)));
    }

    private ResourceDictionary res
    {
        get
        {
            return new ResourceDictionary() { Source = new Uri("pack://application:,,,/Vampirewal.Core.WPF.Theme;component/Theme.xaml", UriKind.RelativeOrAbsolute) };
        }
    }

    public TitleContent()
    {
        //构造函数
        var TitleContentStyle = res["TitleContentStyle"] as Style;

        this.Style = TitleContentStyle;
    }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        //var title = this.Template.FindName("Title", this) as TextBlock;
        //title.Text = Title;
        //if (TitleWidth > 0)
        //{
        //    //title.Width = TitleWidth;
        //    Binding widthBind = new Binding("TitleWidth");
        //    widthBind.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor);
        //    widthBind.RelativeSource.AncestorType = typeof(TitleContent);
        //    title.SetBinding(TextBlock.WidthProperty, widthBind);
        //}
    }

    public string Title
    {
        get { return (string)GetValue(TitleProperty); }
        set { SetValue(TitleProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Title.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TitleProperty =
        DependencyProperty.Register("Title", typeof(string), typeof(TitleContent), new PropertyMetadata(""));

    private static void TitlePropertyCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (d is TitleContent && e.NewValue != null)
        {
            var control = d as TitleContent;
            control.SetValue(TitleContent.TitleProperty, e.NewValue);
        }
    }

    public double TitleWidth
    {
        get { return (double)GetValue(TitleWidthProperty); }
        set { SetValue(TitleWidthProperty, value); }
    }

    // Using a DependencyProperty as the backing store for TitleWidth.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TitleWidthProperty =
        DependencyProperty.Register("TitleWidth", typeof(double), typeof(TitleContent), new PropertyMetadata(0d));

    private static void TitleWidthCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (d is TitleContent && e.NewValue != null)
        {
            var control = d as TitleContent;
            control.SetValue(TitleContent.TitleWidthProperty, e.NewValue);
        }
    }

    public VerticalAlignment TitleVerticalAlignment
    {
        get { return (VerticalAlignment)GetValue(MyPropertyProperty); }
        set { SetValue(MyPropertyProperty, value); }
    }

    // Using a DependencyProperty as the backing store for TitleVerticalAlignment.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty MyPropertyProperty =
        DependencyProperty.Register("TitleVerticalAlignment", typeof(VerticalAlignment), typeof(TitleContent), new PropertyMetadata(VerticalAlignment.Center));

    public Thickness TitlePadding
    {
        get { return (Thickness)GetValue(TitlePaddingProperty); }
        set { SetValue(TitlePaddingProperty, value); }
    }

    // Using a DependencyProperty as the backing store for TitlePadding.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TitlePaddingProperty =
        DependencyProperty.Register("TitlePadding", typeof(Thickness), typeof(TitleContent), new PropertyMetadata(new Thickness(0, 0, 10, 0)));

    public Brush TitleForeground
    {
        get { return (Brush)GetValue(TitleForegroundProperty); }
        set { SetValue(TitleForegroundProperty, value); }
    }

    // Using a DependencyProperty as the backing store for TitleForeground.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TitleForegroundProperty =
        DependencyProperty.Register("TitleForeground", typeof(Brush), typeof(TitleContent), new PropertyMetadata(Brushes.Black));
}